package com.ygk.bluepath.member.Presenter;

import com.ygk.bluepath.R;
import com.ygk.bluepath.core.BFragment;
import com.ygk.bluepath.core.BPresenterFragment;
import com.ygk.bluepath.core.BView;
import com.ygk.bluepath.member.View.RegisterActivity;

import cn.smssdk.EventHandler;
import cn.smssdk.SMSSDK;
import utils.LogUtils;

/**
 * Created by Handreace on 16-7-13.
 */
public class RegisterPresenterFragmentOne extends BPresenterFragment {
    public RegisterPresenterFragmentOne(BFragment fragment, BView mView) {
        super(fragment, mView);
    }

    public void sendCode(String mobile) {
        if (mobile.length() != 11) {
            tt(fragment.getResources().getString(R.string.wrongNumber));
            return;
        } else {
            SMSSDK.getVerificationCode("86", mobile);
        }
    }
    public void submitCode(String mobile, String code) {



        ((RegisterActivity)getActivity()).changeFragment(1);//跳转到注册第二步
        return;
        //注释掉上面代码,下面的才是真实的
       /* if (mobile.length() != 11) {
            tt(fragment.getResources().getString(R.string.wrongNumber));
            return;
        } else {
            SMSSDK.submitVerificationCode("86", mobile,code);
            ((RegisterActivity) getActivity()).setMobileNum(mobile);
             ((RegisterActivity) getActivity()).setCode(code);
        }*/
    }

    public void initMob() {
        SMSSDK.initSDK(getActivity(), "136588e1b0093", "63bc9539531cf7fb7e634f65f3caf0f5",false);
        EventHandler eh = new EventHandler() {

            @Override
            public void afterEvent(int event, int result, Object data) {
                LogUtils.e("data____"+data.toString());
                if (result == SMSSDK.RESULT_COMPLETE) {
                    //回调完成
                    if (event == SMSSDK.EVENT_SUBMIT_VERIFICATION_CODE) {
                        //提交验证码成功
                        tt("验证码验证成功");
                        LogUtils.e("提交验证码成功");
                        ((RegisterActivity)getActivity()).changeFragment(1);//跳转到注册第二步
                    } else if (event == SMSSDK.EVENT_GET_VERIFICATION_CODE) {
                        //获取验证码成功
                        tt("获取验证码成功");
                        LogUtils.e("获取验证码成功");
                    } else if (event == SMSSDK.EVENT_GET_SUPPORTED_COUNTRIES) {
                        //返回支持发送验证码的国家列表
                    }
                } else {
                    LogUtils.e("失败____"+data.toString());
                }
            }
        };
        SMSSDK.registerEventHandler(eh); //注册短信回调
    }
    public void unregisterMob() {
        SMSSDK.unregisterAllEventHandler();
    }


}
